﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- InstanceBegin template="/Templates/ezdesk_app_template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <!-- InstanceBeginEditable name="pageTitle" -->
    <title>易得桌面</title>
    <!-- InstanceEndEditable -->
    <link href="Content/jquery-ui.custom.css" rel="stylesheet" type="text/css" />
    <link href="Content/ui.textbox.css" type="text/css" rel="stylesheet" media="all" />
    <link href="Content/freecontent.css" rel="stylesheet" type="text/css" />
    <link href="Content/wdatepicker.css" rel="stylesheet" type="text/css" />
    <link href="Content/ajaxbusy.css" rel="stylesheet" type="text/css" />
    <link href="Content/Site.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/ezdesk_mockdata.js" type="text/javascript"></script>
    <script src="Scripts/jquery.js" type="text/javascript"></script>
    <script src="Scripts/jquery-ui.custom.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery.form.js" type="text/javascript"></script>
    <script src="Scripts/ui.textbox.js" type="text/javascript"></script>
    <script src="Scripts/pinyin.js" type="text/javascript"></script>
    <script src="Scripts/ezdesk-jquery-ui.js" type="text/javascript"></script>
    <script src="Scripts/ezdesk_common.js" type="text/javascript"></script>
</head>
<!-- InstanceBeginEditable name="pageStyles" -->
<style type="text/css">
    
</style>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="pageScripts" -->
<link href="Content/userInfoSelect.css" rel="stylesheet" type="text/css" />
<script src="Content/xheditor/xheditor-zh-cn.js" type="text/javascript"></script>
<script type="text/javascript">

    //************* URL常量

    var URL_MESSAGE_SEND = '/Message/DoSend';

    //************* 全局变量

    var g_Var = {
        'currentTime': null,
        'currentUser': null,
        'recieverId': 'everyone'

    };

    //************* 常量定义

    //************* Accessor访问器

    var EzAccessor = {};

    if (ezmock.IS_MOCKED) {
        var mock_currentTime = { "CurrentTime": 1348423559 };
        var mock_currentUser =
            {
                "Id": "22222",
                "Name": "李7",
                "UserName": "yuxin",
                "Dept":
                 {
                     "Id": "bd3474a8-6c2d-43ef-bf42-b06827a216f6",
                     "DeptName": "软件工程",
                     "GroupId": "9ad96dac-88d8-4315-bfdb-9931c8f3cb7c"
                 }

            };

        var mockEzAccessor = {

            'doSendMessage': function () {
                var stateInfo = { "State": "Success", "Info": "发送成功！", "Data": null };
                $.displayStateInfo(stateInfo);

            }
        };


        EzAccessor = mockEzAccessor;

    } else {
        var realEzAccessor = {

            'doSendMessage': function () {
                //获得标题
                var title = "";
                if (!$('#messageTitle').defaultText()) {
                    title = $('#messageTitle').val();
                }

                //获得内容
                var text = $('#messageContent').val();

                //获得是否需要确认
                var needConfirm = false;
                if ($('#isNeedToAffirm').attr("checked") == true) {
                    needConfirm = true;
                }

                //获得收件人名单
                var memberString = g_Var['recieverId'];

                //发送消息
                $('.page-submit').ajaxBusyProgress();

                $.post(URL_MESSAGE_SEND,
                {
                    'memberString': memberString,
                    'messageTitle': title,
                    'messageText': text,
                    'needConfirm': needConfirm
                }, function (e) {
                    if (e.State == "Success") {
                        var url = '/message/show?topicId={topicId}';
                        url = url.replace("{topicId}", e.Data.topicId);
                        $.redirectAndDisplayInfo(url, e);
                    } else {
                        $.displayStateInfo(e);
                        $('.page-submit').ajaxBusyProgress('reset');
                    }
                });

            }
        };

        EzAccessor = realEzAccessor;
    }

    function chooseMembersCallBack(selectedMembers) {
        // 将选中的用户加入收信人列表
        var members = [];
        var Namelist = "";

        var IdArray = [];

        $(selectedMembers)
            .each(function (index, item) {
                members[members.length] = item.Name;
                Namelist += "<p> " + item.Name + " </p> ";
                IdArray[IdArray.length] = item.Id;

            });

        g_Var['recieverId'] = IdArray.join(',');
        if (g_Var['recieverId'].length == 0) {
            g_Var['recieverId'] = "everyone";
        }

        $('#receiver').show();
        if (Namelist != []) {
            $('#receiver').html(Namelist)
        }
        else {
            $('#receiver').html("所有人");
        }
    }


    //判断回复是否为空
    function checkForm() {
        if ($("#messageContent").val().length == 0) {
            var stateInfo = { 'State': 'Error', 'Info': '消息内容不能为空!', 'Date': null };
            $.displayStateInfo(stateInfo);

            return false;
        }
        return true;
    }


    function initPageEvent() {
        var addresseeSelector = new EzUserInfoSelector(chooseMembersCallBack);
        addresseeSelector.initialize();

        // 选择收信人点击事件
        $('#btnChooseAddressee').click(function () {
            addresseeSelector.Show();
        });

        // 创建发送消息按钮的点击事件
        $('#btnSubmit').click(function () {
            var messageConfirm = checkForm();
            if (messageConfirm) {
                EzAccessor.doSendMessage();
            }
        });

        //重设
        $('#btnRecover').click(function () {
            //清空标题和内容
            $('#messageTitle').clearFields();
            $('#messageContent').val("");
            //重设memberSelcet
            chooseMembersCallBack(null);
            //取消选中的消息需要确认
            $('#isNeedToAffirm').attr('checked', '');
            EzTipsManager.hideTipBox('tipNeedConfirm');
            //隐藏标题
            $('#deleTtiel').parent().hide();
            $('#addTitel').show();
        });


        //增添标题
        $('#addTitel').click(function () {
            $(this).next().show();
            $(this).hide();
        });
        //取消标题
        $('#deleTtiel').click(function () {
            $(this).parent().hide();
            $('#addTitel').show();
            $('#messageTitle').empty();

        });

        $('#lblChecked').click(function () {
            if ($('#isNeedToAffirm').attr("checked") == true) {
                EzTipsManager.showTipBox('tipNeedConfirm');
            } else {
                EzTipsManager.hideTipBox('tipNeedConfirm');
            }
        });


    }



    function initPage() {
        $('#messageContent').xheditor({ tools: 'Fontface,FontSize,Bold,Italic,Underline,FontColor,BackColor,Align,Emot' });

        EzTipsManager.addTipBox('#tip_Receiver', 'tipReceiver');
        EzTipsManager.addTipBox('#tip_NeedConfirmOrNot', 'tipNeedConfirmOrNot');
        EzTipsManager.addTipBox('#tip_NeedConfirm', 'tipNeedConfirm');


        EzTipsManager.showTipBox('tipReceiver');
        EzTipsManager.showTipBox('tipNeedConfirmOrNot');

        $('#messageContent').focus();

    }


    $(function () {
        initPage();
        initPageEvent();


    });

</script>
<!-- InstanceEndEditable -->
<body>
    <div id="root">
        <div id="headw">
            <div id="head">
                <!-- InstanceBeginEditable name="pageHead" -->
                <p>
                    早上好，杨裕欣(软件工程部)
                </p>
                <div id="status-bar">
                    <span><a href="#">设置</a></span>&nbsp; 魏玛软件出品
                </div>
                <!-- InstanceEndEditable -->
            </div>
        </div>
        <div id="main">
            <div id="contentw">
                <div id="content-page">
                    <!-- InstanceBeginEditable name="pageContent" -->
                    <div id="page-head">
                        <img src="Content/icons/message_send.png" style="width: 48px; height: 48px;" alt="send" />
                        <span>发送新消息</span>
                    </div>
                    <div id="page-body">
                        <div class="formBox">
                            <a id="addTitel">添加标题</a>
                            <div style="display: none;">
                                标题
                                <input type="text" id="messageTitle" style="width: 300px;" />
                                <a id="deleTtiel">取消标题</a>
                            </div>
                            <div id="text" class="r">
                                <textarea id="messageContent" style="width: 100%; height: 200px;"></textarea>
                            </div>
                        </div>
                    </div>
                    <div class="page-submit">
                        <input id="btnSubmit" type="submit" value="发送" />
                        &nbsp;或者&nbsp;<a id="btnRecover">重置</a>
                    </div>
                    <!-- InstanceEndEditable -->
                </div>
                <div id="content-foot">
                    <small>这个是内容下面的脚注</small></div>
            </div>
            <div id="tipsw">
                <!-- InstanceBeginEditable name="pageShortcut" -->
                <!-- InstanceEndEditable -->
                <div id="tips" class="box">
                </div>
            </div>
            <div class="clearfloat">
            </div>
        </div>
    </div>
    <!-- InstanceBeginEditable name="pageFoot" -->
    <div id="tip_Receiver" style="display: none;">
        <div id="messageContainer" style="margin-top: 10px; margin-bottom: 10px;">
            <a id="btnChooseAddressee" href="#">选择收件人</a>
        </div>
        <h1>
            该消息发送给:</h1>
        <p id="receiver" class="indent">
            所有人</p>
    </div>
    <div id="tip_NeedConfirmOrNot" style="display: none;">
        <h1>
            消息是否需要被确认？
            <label id="lblChecked" for="isNeedToAffirm">
                <input type="checkbox" id="isNeedToAffirm" /><label for="isNeedToAffirm">需要</label></h1>
    </div>
    <div id="tip_NeedConfirm" style="display: none;" class="tip-info">
        <h1>
            该消息需要被确认！</h1>
    </div>
    <!-- InstanceEndEditable -->
</body>
<!-- InstanceEnd -->
</html>
